package com.example.entity;

import org.springframework.util.StringUtils;

import java.io.Serializable;
import java.util.Date;

public class Metadata implements Serializable {
    private static final long serialVersionUID = 6868467274016712562L;

    /**
     * 授权
     */
    private Authorization authorization;

    /**
     * 终端
     */
    private Terminal terminal;

    public Authorization getAuthorization() {
        return authorization;
    }

    public void setAuthorization(Authorization authorization) {
        this.authorization = authorization;
    }

    public Terminal getTerminal() {
        return terminal;
    }

    public void setTerminal(Terminal terminal) {
        this.terminal = terminal;
    }

    public boolean isValid() {
        return (authorization != null) && !StringUtils.isEmpty(authorization.accessToken) &&
                (terminal != null) && !StringUtils.isEmpty(terminal.appId);
    }

    public static class Authorization implements Serializable {
        private static final long serialVersionUID = 3156933153483984092L;
        /**
         * 访问令牌
         */
        private String accessToken;
        /**
         * 时间戳
         */
        private Date timeStamp;

        public String getAccessToken() {
            return accessToken;
        }

        public void setAccessToken(String accessToken) {
            this.accessToken = accessToken;
        }

        public Date getTimeStamp() {
            return timeStamp;
        }

        public void setTimeStamp(Date timeStamp) {
            this.timeStamp = timeStamp;
        }
    }

    public static class Terminal implements Serializable {
        private static final long serialVersionUID = -716753169370478931L;
        /**
         * 应用标识
         *
         * @see com.orgdeer.cui.services.api.model.ApplicationType
         */
        private Integer appId;
        /**
         * 应用版本
         */
        private String version;

        public Integer getAppId() {
            return appId;
        }

        public void setAppId(Integer appId) {
            this.appId = appId;
        }

        public String getVersion() {
            return version;
        }

        public void setVersion(String version) {
            this.version = version;
        }
    }
}